﻿/*----------------------
 * Author : Dhanushka
 * Comapny : LongdenSolutions
 * date : 18-04-2011
 * purpose : Db connection
 * */
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;


public class DbConnet
{


    public static SqlConnection conn_new = new SqlConnection();

    public static SqlConnection connect(string strConStr)
    {
        try
        {
            if (conn_new.State != System.Data.ConnectionState.Open)
            {
                conn_new.ConnectionString = strConStr;
                conn_new.Open();
            }
            else
            {
                return null;
            }
            return conn_new;
        }
        catch (Exception ex)
        {
            return null;
            //mess.Show(ex.Message, "Connecting To The Server", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
       
    }

    public static SqlDataReader ReadTable(string strReadStr)
    {
        SqlCommand COMMA = new SqlCommand(strReadStr, conn_new);
        SqlDataReader rdNew;
        rdNew = COMMA.ExecuteReader();
        return rdNew;
    }

    public static Boolean AddEditDel(string strAddEditDel)
    {
        SqlCommand ADDCOM = new SqlCommand(strAddEditDel, conn_new);
        int a;
        a = ADDCOM.ExecuteNonQuery();
        if (a == 0)
            return false;
        else
            return true;

    }

    public static double RecCount(SqlDataReader drReader)
    {
        double a = 0;

        while (drReader.Read())
            a++;
        drReader.Close();
        return a;
    }

    public static SqlDataReader RecMove(string strReadStr, int movRec)
    {

        SqlCommand COMMB = new SqlCommand(strReadStr, conn_new);
        SqlDataReader rdNew1;
        rdNew1 = COMMB.ExecuteReader();

        for (int x = 1; x < movRec; x++)
        {
            rdNew1.Read();
        }
        return rdNew1;
    }

    public static int userloginfunc(String funcall)
    {
        SqlCommand COMMA = new SqlCommand(funcall, conn_new);
        int count = COMMA.ExecuteNonQuery();
        return count;
    }
}